package cn.manyufun.myf.common.commonutils;

import cn.manyufun.myf.bean.UserSummary;

/**
 * @author Kevin Xiao
 * @date Create Date: 2018-02-01
 * @Description
 */
public class UserInfoUtils {
    private static final String TAG = "USERINFOUTILS";

    private UserInfoUtils() {

    }

    private static UserInfoUtils instance;

    public static UserInfoUtils getInstance() {
        if (instance == null) {
            synchronized (UserInfoUtils.class) {
                if (instance == null) {
                    instance = new UserInfoUtils();
                }
            }
        }
        return instance;
    }

    public String getToken() {
        UserSummary user = UserSummary.first(UserSummary.class);
        if (user != null)
            return user.UserToken;
        return "";
    }

    public String getOpenid() {
        UserSummary user = UserSummary.first(UserSummary.class);
        if (user != null)
            return user.OpenId;
        return "";
    }

    public UserSummary getUser() {
        UserSummary user = UserSummary.first(UserSummary.class);
        if (user != null)
            return user;
        return null;
    }

    public boolean checkLogin() {
        UserSummary user = UserSummary.first(UserSummary.class);
        return user != null;
    }

    public void logout() {
        UserSummary.deleteAll(UserSummary.class);
    }

    public void modify(UserSummary userSummary) {
        UserSummary.deleteAll(UserSummary.class);
        userSummary.save();

    }
}
